﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;
using System.IO;

namespace PhysicsSimulator
{
    public class ThrowObliqueData
    {
        private const string filename = "throwobliquedata.xml";
        public string Name;
        public float Angle;//góc ngiêng
        public float Velocity;//vận tốc đầu
        public float Gravity;//
        public float HeightFirst;// độ cao ban đầu

        public ThrowObliqueData()
        {
        }
        public ThrowObliqueData(string name, float angle, float velocity, float gravity, float heightfist)
        {
            Name = name;
            Angle = angle;
            Velocity = velocity;
            Gravity = gravity;
            HeightFirst = heightfist;
        }

        public static bool SaveData(List<ThrowObliqueData> list)
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream stream = storage.CreateFile(filename);
            XmlSerializer xml = new XmlSerializer(typeof(List<ThrowObliqueData>));
            xml.Serialize(stream, list);
            stream.Close();
            stream.Dispose();
            return true;
        }

        public static List<ThrowObliqueData> Load()
        {
            List<ThrowObliqueData> data = new List<ThrowObliqueData>();
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            if (storage.FileExists(filename))
            {
                FileStream stream = storage.OpenFile(filename, FileMode.Open);
                XmlSerializer xml = new XmlSerializer(typeof(List<ThrowObliqueData>));

                data = xml.Deserialize(stream) as List<ThrowObliqueData>;

                stream.Close();
                stream.Dispose();
            }
            else
            {
                return new List<ThrowObliqueData>();
            }
            return data;
        }
    }
}
